import {takeEvery,put} from 'redux-saga/effects';
import axios from 'axios';
import {Map} from 'immutable';
import { loadDataSync, delDataSaga, changeDataSaga } from './actionCreator';
function* loadData(action){
    const res = yield axios.get('/api/' + action.dataType)
    yield put(loadDataSync(Map(res.data)))
    
}

function* delData(action) {
    yield put(delDataSaga(action.key));
}

function* setLoadData(action) {
    const res = yield axios.patch('/api/' + action.dataType,
        {'data':action.data} )
    yield put(loadDataSync(Map(res.data)))
}

function* changeData(action) {
    yield put(changeDataSaga(action.key, action.value));
}

function * detailSaga(){
    yield takeEvery('loadDataSagaMonitoring',loadData);
    yield takeEvery('delDataSagaMonitoring', delData);
    yield takeEvery('setLoadDataMonitoring', setLoadData);
    yield takeEvery('changeDataMonitoring', changeData);

}
export default detailSaga